package com.acando.feide;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.acando.feide.jaxb.OperationType;

/**
 * Class representing one entry in the LDIF file
 * @author benand
 *
 */
public class LDIFEntry {
    
    // Source id, an id created by the source system that created input data
    private String id;
    // LDAP Distinguised Name
    private String dn;
    // Type of LDAP operation    add/modify/delete
    private OperationType operationType;
    // List of items representing LDAP attributes
    private List<LDIFItem> items = new ArrayList<LDIFItem>();
    // Map of attributes. Names of LDAP attributes is key and LDIFItem is value.
    private Map<String, LDIFItem> attributeMap = new HashMap<String, LDIFItem>();

    public LDIFEntry(OperationType operationType) {
        super();
        this.operationType = operationType;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<LDIFItem> getItems() {
        return items;
    }

    public void addItem(LDIFItem item) {
        this.items.add(item);
        this.attributeMap.put(item.getLdapAttribute(), item);
    }

    public String getDn() {
        return dn;
    }

    public void setDn(String dn) {
        this.dn = dn;
    }

    public LDIFItem findItem(String attributeName) {
        return attributeMap.get(attributeName);
    }

    public OperationType getOperationType() {
        return operationType;
    }

}
